package com.sbl.bajw.pc.service;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sbl.bajw.common.MyBatisDao;
import com.sbl.bajw.common.web.SessionUnit;
import com.sbl.bajw.mapper.RoleDao;
import com.sbl.bajw.mapper.UserRoleDao;
import com.sbl.bajw.pc.model.RoleModel;

@Service
public class RoleService {
	
	@Resource
	private RoleDao dao;
	
	@Resource
	private UserRoleDao urdao;
	
	@Resource 
	private MyBatisDao gridDao;
	
	@Resource 
	private PrivilegeService pService;
	
	public void insert(RoleModel model){
		model.setCreater(SessionUnit.getUserId());
		dao.insert(model);
	}
	
	public void update(RoleModel model){
		dao.update(model);
	}
	
	public String list(){
		String result = gridDao.selectPage(RoleDao.class, null, "list");
		return result;
	}
	
	@Transactional
	public void delete(String id){
		dao.delete(id);
		dao.deleteRoleUser(id);
		pService.initPrivilegeMap();
	}
}
